#include "SeqList.h"


void SeqListNotInit(SLN*ps)//初始化
{
    ps->data=NULL;
    ps->capacity=0;
    ps->size=0;
}


void SeqListNotDestroy(SLN*ps)//销毁
{
    free(ps->data);
    ps->data=0;
    ps->size=0;
}

void SeqListNotSpace(SLN*ps)//开辟空间
{
    if(ps->size==ps->capacity)
    {
        int newcapacity=ps->capacity==0?4:ps->capacity*2;
        ps->data=(Value*)malloc(sizeof(Value)*newcapacity);
        ps->capacity=newcapacity;
    }
}

int  SeqListNotFind(SLN*ps,int num)//查
{
    for(int i =0;i<ps->size;i++)
    {
        if(num==ps->data[i])
        {
            return i;
        }
    }
    return -1;
}

void SeqListNotPushBack(SLN*ps,int num)//尾插
{

    SeqListNotSpace(ps);//开辟空间
    ps->data[ps->size]=num;
    ps->size++;
}

void SeqListNotPopBack(SLN*ps,int num)//尾删
{
    assert(ps->size==0&&ps->capacity==0);
    ps->size--;
}

void SeqListNotPushFront(SLN*ps,int num)//头插
{
    //防止满了或者没有的情况
    SeqListNotSpace(ps);
    for (int i = 0; i <ps->size ; ++i)
    {
        ps->data[ps->size+1]=ps->data[ps->size];
    }
    ps->data[0]=num;
    ps->size++;
}

void SeqListNotPopFront(SLN*ps,int num)//头删
{
    //防止满了或者没有的情况
     assert(ps->size&&ps->capacity);
    for (int i = 0; i <ps->size ; ++i)
    {
        ps->data[i]=ps->data[i+1];
    }
    ps->size--;
}


void SeqListNotPushInsert(SLN*ps,int find,int num)//任意位置插入
{
    //防止满了或者没有的情况
    int count=ps->size-find;
    int tail=ps->size;
     while(count--)
     {
         ps->data[tail+1]=ps->data[tail];
         tail--;
     }
     ps->size++;
}

void SeqListNotPopInsert(SLN*ps,int find,int num)//任意位置删
{

   int trade=find;
   int count=ps->size-find-1;
    while(count--)
    {
       ps->data[trade]=ps->data[trade+1];
       trade++;
    }
    ps->size--;
}